package com.design.blog.controller;

import com.design.blog.model.R;
import com.design.blog.model.vo.CategoryParams;
import com.design.blog.model.vo.PageNationParams;
import com.design.blog.service.impl.ArticleServiceImpl;
import com.design.blog.service.impl.CommentServiceImpl;
import com.design.blog.service.impl.UserinfoServiceImpl;
import com.design.blog.utils.JWTUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private UserinfoServiceImpl userinfoService;

    @Resource
    private ArticleServiceImpl articleService;

    @Resource
    private CommentServiceImpl commentService;

    @Resource
    private RedisTemplate redisTemplate;

    @PostMapping("getAllUseInfo")
    public R getAllUseInfo(@RequestBody PageNationParams params) {
        return R.success(userinfoService.getAllUseInfo(params));
    }

    @GetMapping("deleteUser/{id}")
    public R deleteUser(@PathVariable("id") String id) {
        redisTemplate.delete(id);
        return R.success(userinfoService.removeById(id));
    }


    @PostMapping("getAllUseArticle")
    public R getAllUseArticle(@RequestBody PageNationParams params) {
        return R.success(articleService.getAllUseArticle(params));
    }

    @GetMapping("deleteUserArticle/{id}")
    public R deleteUserArticle(@PathVariable("id") String id) {
        return R.success(articleService.removeById(id));
    }

    @PostMapping("getAllUseComment")
    public R getAllUseComment(@RequestBody PageNationParams params) {
        return R.success(commentService.getAllUseComment(params));
    }

    @GetMapping("deleteUserComment/{id}")
    public R deleteUserComment(@PathVariable("id") String id) {
        return R.success(commentService.removeById(id));
    }

    @PostMapping("chgArticleCategory/{id}")
    public R chgArticleCategory(@PathVariable("id") String id,
                                @RequestBody CategoryParams params) {
        return R.success(articleService.chgArticleCategory(id, params.getType().get(0)));
    }

}
